package cn.cms.chuangjia.controller;

import cn.cms.chuangjia.domain.Admin;
import cn.cms.chuangjia.util.StrUtil;
import cn.cms.chuangjia.vo.AjaxResult;
import com.github.pagehelper.PageHelper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author oldliu
 * @since 1.0
 */
public class BaseController {
    public void startPage() {
        HttpServletRequest request =
                ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");
        int pageNo = StrUtil.toInt(page, 1);
        int pageSize = StrUtil.toInt(limit, 10);
        PageHelper.offsetPage(pageSize * (pageNo - 1), pageSize);
    }
    public Admin getUser(){
        HttpServletRequest request =
                ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        return (Admin) request.getSession().getAttribute("Admin");
    }

}
